/**=========================================================================
  日志系统头文件：使用log4qt管理自己的日志系统，需要引入库文件: log4qt.dll
=========================================================================*/
#ifndef MELOGGER_H
#define MELOGGER_H

#include <QDebug>
#include <QFile>

#include <log4qt/logger.h>
#include <log4qt/logmanager.h>
#include <log4qt/loggerrepository.h>
#include <log4qt/propertyconfigurator.h>

namespace Me {
    /** 默认的logger */
    inline Log4Qt::Logger *defaultLogger()
    {
        static Log4Qt::Logger * p_logger = Log4Qt::Logger::logger("default");
        return p_logger;
    }

    inline bool setupRootLogger(QString configFile)
    {
        //QString configFile = QCoreApplication::applicationDirPath() + QStringLiteral("log4qt.properties");
        qDebug() << "configFile:" << configFile;
        if (QFile::exists(configFile))
            Log4Qt::PropertyConfigurator::configureAndWatch(configFile);
        return true;
    }

    inline void releaseAllLogger()
    {
        // 获取 rootLogger
        Log4Qt::Logger* logger = Log4Qt::Logger::rootLogger();

        // 关闭 rootLogger
        logger->removeAllAppenders();
        logger->loggerRepository()->shutdown();
    }

}

#endif // MELOGGER_H
